//
//  JWTDefaultNoDataView.m
//  JWT
//
//  Created by ndm on 17/2/13.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTDefaultNoDataView.h"

@implementation JWTDefaultNoDataView
SHARED_INSTANCE_IMPLEMENTATION(JWTDefaultNoDataView);

/**是否显示没有数据的图片提示,图片下面显示一行文件*/
-(void)showNoDataWithView:(UIView *)view andImageName:(NSString *)imageName andTitle:(NSString *)title{
    
    UIButton* nodataImageView = (UIButton *)[view viewWithTag:404];
    if(! nodataImageView)
    {
        nodataImageView = [[UIButton alloc] initWithFrame:CGRectMake(0,0, rem(100), rem(100))];
        nodataImageView.tag = 404;
        [view addSubview:nodataImageView];
        [view sendSubviewToBack:nodataImageView];
        nodataImageView.imageView.contentMode = UIViewContentModeScaleAspectFill;
//        nodataImageView.clipsToBounds = YES;
//        nodataImageView.layer.cornerRadius = nodataImageView.height/2;
    }
    nodataImageView.enabled = NO;
    if(! isEmpty(imageName))
        [nodataImageView setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    else
        [nodataImageView setBackgroundImage:[UIImage imageNamed:ImageViewDefault] forState:UIControlStateNormal];
    nodataImageView.center = CGPointMake(view.width/2, 190);
    //
    UILabel *hintLable = (UILabel *) [view viewWithTag:405];
    if(! hintLable)
    {
        hintLable = [[UILabel alloc] initWithFrame:CGRectMake(10, nodataImageView.top + nodataImageView.height + 5, view.width - 20, 30)];
        hintLable.tag = 405;
        [view addSubview:hintLable];
        [view sendSubviewToBack:hintLable];
        hintLable.textAlignment = NSTextAlignmentCenter;
        hintLable.numberOfLines = 3;
    }
    hintLable.textColor = RGB(170, 170, 170);
    if(isEmpty(title))
    {
        hintLable.text = @"暂无数据";
    }
    else
        hintLable.text = title;
    
    CGSize rsize = [hintLable getLabelContentSize];
    hintLable.frame = CGRectMake(10, nodataImageView.top + nodataImageView.height + 5, view.width - 20, rsize.height + 2);
}

/**不显示没有数据的图片提示*/
-(void) hideNODATAImageView:(UIView *)view
{
    UIImageView* nodataImageView = (UIImageView *)[view viewWithTag:404];
    if(nodataImageView)
    {
        [nodataImageView removeFromSuperview];
        nodataImageView = nil;
    }
    
    UILabel *hintLable = (UILabel *) [view viewWithTag:405];
    if(hintLable)
    {
        [hintLable removeFromSuperview];
        hintLable = nil;
    }
}


@end
